<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:ui="http://java.sun.com/jsf/facelets"
                template="/resources/template/template.xhtml"
                xmlns:h="http://java.sun.com/jsf/html"
                xmlns:p="http://primefaces.org/ui"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:pe="http://primefaces.org/ui/extensions">

    <ui:define name="content">
        <h:form>
            <p:panel id="panelPrint" styleClass="noBorder summeryBorder" header="Sale Detail by Discount Scheme - #{pharmacySaleReport.paymentScheme.name}">
                <h:panelGrid columns="8" styleClass="noPrintButton">
                    <h:outputLabel value="From Date"/>
                    <p:calendar value="#{pharmacySaleReport.fromDate}" navigator="true" pattern="dd MMMM yyyy hh mm ss a"  >
                    </p:calendar>
                    <h:outputLabel value="To Date"/>
                    <p:calendar value="#{pharmacySaleReport.toDate}" navigator="true" pattern="dd MMMM yyyy hh mm ss a" >
                    </p:calendar>
                    <h:outputLabel value="Department"/>
                    <p:autoComplete styleClass="noPrintButton"  value="#{pharmacySaleReport.department}"  style="text-align: left; margin: 5px; padding: 5px;"  completeMethod="#{departmentController.completeDept}" var="dept" itemValue="#{dept}" itemLabel="#{dept.name}" forceSelection="true" rendered="true" requiredMessage="You must select a department" >
                    </p:autoComplete>
                    <p:selectOneMenu   id="pay" value="#{pharmacySaleReport.paymentMethod}"> 
                        <f:selectItem itemLabel="Payment Method"/>
                        <f:selectItems value="#{enumController.paymentMethods}"/>
                        <!--                        <p:ajax process="@this cmbPs " 
                                                        update="pBillDetails creditCard cheque slip tvPt" 
                                                        event="change"  
                                                        />-->
                    </p:selectOneMenu>

                    <p:selectOneMenu   id="cmbPs" value="#{pharmacySaleReport.paymentScheme}">   
                        <f:selectItem itemLabel="Discount Scheme"/>
                        <f:selectItems value="#{paymentSchemeController.paymentSchemesForPharmacy}" var="i" itemLabel="#{i.name}" itemValue="#{i}"/>
                        <!--                        <p:ajax process="@this pay " 
                                                        update="pBillDetails creditCard cheque slip" 
                                                        event="change"  
                                                        />-->
                    </p:selectOneMenu>
                </h:panelGrid>

                <h:panelGrid columns="3">
                    <p:commandButton ajax="false" value="Process" action="#{pharmacySaleReport.createSaleReportByDateDetailPaymentScheme()}" styleClass="noPrintButton"/>
                    <p:commandButton actionListener="#{pharmacySaleReport.createSaleReportByDateDetailPaymentScheme()}" ajax="false" value="Excel" styleClass="noPrintButton" style="float: right;" >
                        <pe:exporter subTable="true" type="xlsx" target="sum1,sum2,sum3" fileName="sale_report_by_date_detail_payment_scheme"  />
                    </p:commandButton>
                    <p:commandButton ajax="false" value="Print" styleClass="noPrintButton" >
                        <p:printer target="panelPrint" />
                    </p:commandButton>
                </h:panelGrid>

                


                <p:dataTable id="sum1" value="#{pharmacySaleReport.billedDetail.datedBills}" var="i">
                    <f:facet name="header">                        
                        <h:outputLabel value="#{pharmacySaleReport.department.name}"/>
                        <h:outputLabel value=" From - " style=" white-space:pre-line;"/>
                        <h:outputLabel value="#{pharmacySaleReport.fromDate}"  >
                            <f:convertDateTime pattern="dd MMMM yyyy hh mm ss a" />
                        </h:outputLabel>
                        <h:outputLabel value=" - To - " />
                        <h:outputLabel value="#{pharmacySaleReport.toDate}"  >
                            <f:convertDateTime pattern="dd MMMM yyyy hh mm ss a" />
                        </h:outputLabel>
                        <h:outputLabel value="BILLED" style=" white-space:pre-line;"/>
                    </f:facet>

                    <p:columnGroup type="header">
                        <p:row>
                            <p:column headerText="Bill No">
                                <f:facet name="header">
                                    <h:outputLabel value="Bill No"/>
                                </f:facet>
                            </p:column>
                            <p:column headerText="Billed Time">
                                <f:facet name="header">
                                    <h:outputLabel value="Billed Time"/>
                                </f:facet>
                            </p:column>                           
                            <p:column headerText="Payment Method">
                                <f:facet name="header">
                                    <h:outputLabel value="Payment Method"/>
                                </f:facet>
                            </p:column>                           
                            <p:column headerText="Billed Person">
                                <f:facet name="header">
                                    <h:outputLabel value="Billed Person"/>
                                </f:facet>
                            </p:column>                            
                            <p:column headerText="Total">
                                <f:facet name="header">
                                    <h:outputLabel value="Total"/>
                                </f:facet>
                            </p:column>
                            <p:column headerText="Discount">
                                <f:facet name="header">
                                    <h:outputLabel value="Discount"/>
                                </f:facet>
                            </p:column>
                            <p:column headerText="NetTotal">
                                <f:facet name="header">
                                    <h:outputLabel value="NetTotal"/>
                                </f:facet>
                            </p:column>

                        </p:row>
                    </p:columnGroup>

                    <p:subTable value="#{i.bills}" var="b" >
                        <f:facet name="header">
                            <h:outputLabel value="#{i.date}">
                                <f:convertDateTime pattern="dd MMMM yyyy" />
                            </h:outputLabel>
                        </f:facet>
                        <p:column>
                            <h:outputLabel value="#{b.deptId}"/>
                            <h:outputLabel value="#{b.insId}" rendered="#{b.deptId eq null}"/>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{b.createdAt}">
                                <f:convertDateTime pattern="hh mm ss a" />
                            </h:outputLabel>
                        </p:column>
                        
                        <p:column>
                            <h:outputLabel value="#{b.paymentMethod}"/>
                        </p:column>

                        <p:column>
                            <h:outputLabel value="#{b.creater.webUserPerson.name}"/>
                        </p:column>
                        
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.total}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.discount}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.netTotal}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:columnGroup type="footer">
                            <p:row>
                                <p:column colspan="4" footerText="Summary">                                    
                                </p:column>
                                <p:column  footerText="#{i.sumNetTotal+i.sumDiscount}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumNetTotal+i.sumDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column  footerText="#{i.sumDiscount}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column  footerText="#{i.sumNetTotal}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumNetTotal}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                            </p:row>
                        </p:columnGroup>
                    </p:subTable>

                    <p:columnGroup type="footer">
                        <p:row>
                            <p:column footerText="Total" colspan="4"/>
                            <p:column footerText="#{pharmacySaleReport.billedDetail.netTotal+pharmacySaleReport.billedDetail.discount}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.billedDetail.netTotal+pharmacySaleReport.billedDetail.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column footerText="#{pharmacySaleReport.billedDetail.discount}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.billedDetail.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column footerText="#{pharmacySaleReport.billedDetail.netTotal}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.billedDetail.netTotal}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                        </p:row>
                    </p:columnGroup>
                </p:dataTable>

                <p:dataTable id="sum2" value="#{pharmacySaleReport.cancelledDetail.datedBills}" var="i">
                    <f:facet name="header">                        
                        <h:outputLabel value="CANCELLED"/>
                    </f:facet>

                    <p:columnGroup type="header">
                        <p:row>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Bill No"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Billed Time"/>
                                </f:facet>
                            </p:column>  
                            <p:column headerText="Payment Method">
                                <f:facet name="header">
                                    <h:outputLabel value="Payment Method"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Billed Person"/>
                                </f:facet>
                            </p:column>                           
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Total"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Discount"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="NetTotal"/>
                                </f:facet>
                            </p:column>

                        </p:row>
                    </p:columnGroup>

                    <p:subTable value="#{i.bills}" var="b" >
                        <f:facet name="header">
                            <h:outputLabel value="#{i.date}">
                                <f:convertDateTime pattern="dd MMMM yyyy" />
                            </h:outputLabel>
                        </f:facet>
                        <p:column>
                            <h:outputLabel value="#{b.deptId}"/>
                            <h:outputLabel value="#{b.insId}" rendered="#{b.deptId eq null}"/>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{b.createdAt}">
                                <f:convertDateTime pattern="hh mm ss a" />
                            </h:outputLabel>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{b.paymentMethod}"/>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{b.creater.webUserPerson.name}"/>
                        </p:column>                       
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.total}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.discount}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.netTotal}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:columnGroup type="footer">
                            <p:row>
                                <p:column colspan="4" footerText="Summary">                                    
                                </p:column>
                                <p:column  footerText="#{i.sumNetTotal+i.sumDiscount}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumNetTotal+i.sumDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column  footerText="#{i.sumDiscount}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column  footerText="#{i.sumNetTotal}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumNetTotal}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                            </p:row>
                        </p:columnGroup>
                    </p:subTable>

                    <p:columnGroup type="footer">
                        <p:row>
                            <p:column footerText="Total" colspan="4"/>
                            <p:column footerText="#{pharmacySaleReport.cancelledDetail.netTotal+pharmacySaleReport.cancelledDetail.discount}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.cancelledDetail.netTotal+pharmacySaleReport.cancelledDetail.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column footerText="#{pharmacySaleReport.cancelledDetail.discount}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.cancelledDetail.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column footerText="#{pharmacySaleReport.cancelledDetail.netTotal}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.cancelledDetail.netTotal}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                        </p:row>
                    </p:columnGroup>
                </p:dataTable>

                <p:dataTable id="sum3" value="#{pharmacySaleReport.refundedDetail.datedBills}" var="i">
                    <f:facet name="header">                        
                        <h:outputLabel value="REFUNDED"/>
                    </f:facet>

                    <p:columnGroup type="header">
                        <p:row>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Bill No"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Billed Time"/>
                                </f:facet>
                            </p:column>  
                            <p:column headerText="Payment Method">
                                <f:facet name="header">
                                    <h:outputLabel value="Payment Method"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Billed Person"/>
                                </f:facet>
                            </p:column>                           
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Total"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="Discount"/>
                                </f:facet>
                            </p:column>
                            <p:column>
                                <f:facet name="header">
                                    <h:outputLabel value="NetTotal"/>
                                </f:facet>
                            </p:column>

                        </p:row>
                    </p:columnGroup>

                    <p:subTable value="#{i.bills}" var="b" >
                        <f:facet name="header">
                            <h:outputLabel value="#{i.date}">
                                <f:convertDateTime pattern="dd MMMM yyyy" />
                            </h:outputLabel>
                        </f:facet>
                        <p:column>
                            <h:outputLabel value="#{b.deptId}"/>
                            <h:outputLabel value="#{b.insId}" rendered="#{b.deptId eq null}"/>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{b.createdAt}">
                                <f:convertDateTime pattern="hh mm ss a" />
                            </h:outputLabel>
                        </p:column>         
                        <p:column>
                            <h:outputLabel value="#{b.paymentMethod}"/>
                        </p:column>
                        <p:column>
                            <h:outputLabel value="#{b.creater.webUserPerson.name}"/>
                        </p:column>                       
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.total}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.discount}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:column style="text-align: right;">
                            <h:outputLabel value="#{b.netTotal}">
                                <f:convertNumber pattern="#,##0.00" />
                            </h:outputLabel>
                        </p:column>
                        <p:columnGroup type="footer">
                            <p:row>
                                <p:column colspan="4" footerText="Summary">                                    
                                </p:column>
                                <p:column  footerText="#{i.sumNetTotal+i.sumDiscount}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumNetTotal+i.sumDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column  footerText="#{i.sumDiscount}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumDiscount}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                                <p:column  footerText="#{i.sumNetTotal}" style="text-align: right;">
                                    <f:facet name="footer">
                                        <h:outputLabel value="#{i.sumNetTotal}">
                                            <f:convertNumber pattern="#,##0.00" />
                                        </h:outputLabel>
                                    </f:facet>
                                </p:column>
                            </p:row>
                        </p:columnGroup>
                    </p:subTable>

                    <p:columnGroup type="footer">
                        <p:row>
                            <p:column footerText="Total" colspan="4"/>
                            <p:column footerText="#{pharmacySaleReport.refundedDetail.netTotal+pharmacySaleReport.cancelledDetail.discount}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.refundedDetail.netTotal+pharmacySaleReport.cancelledDetail.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column footerText="#{pharmacySaleReport.refundedDetail.discount}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.refundedDetail.discount}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                            <p:column footerText="#{pharmacySaleReport.refundedDetail.netTotal}" style="text-align: right;">
                                <f:facet name="footer">
                                    <h:outputLabel value="#{pharmacySaleReport.refundedDetail.netTotal}">
                                        <f:convertNumber pattern="#,##0.00" />
                                    </h:outputLabel>
                                </f:facet>
                            </p:column>
                        </p:row>
                    </p:columnGroup>
                </p:dataTable>

                <h:panelGrid columns="2" style="min-width: 100%;">
                    <h:outputLabel value="Final Total"/>
                    <h:outputLabel value="#{pharmacySaleReport.grantDiscount+pharmacySaleReport.grantNetTotal}" style="text-align: right;">
                        <f:convertNumber pattern="#,##0.00" />
                    </h:outputLabel>
                    <h:outputLabel value="Final Discount"/>
                    <h:outputLabel value="#{pharmacySaleReport.grantDiscount}" style="text-align: right;">
                        <f:convertNumber pattern="#,##0.00" />
                    </h:outputLabel>
                    <h:outputLabel value="Final NetTotal"/>
                    <h:outputLabel value="#{pharmacySaleReport.grantNetTotal}" style="text-align: right;">
                        <f:convertNumber pattern="#,##0.00" />
                    </h:outputLabel>

                </h:panelGrid>

            </p:panel>         


        </h:form>

    </ui:define>



</ui:composition>
